//
//  MationListTableViewController.m
//  CarStop
//
//  Created by lanou3g on 15/7/21.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "MationListTableViewController.h"
#import "ScrollTableViewCell.h"
#import "NewestTableViewCell.h"
#import "RequestMessageData.h"
#import "MationList.h"

@interface MationListTableViewController ()

@property (nonatomic, retain)NSMutableArray *alsoListArray;
@property (nonatomic, retain)NSMutableArray *scrollPicArray;

@property (nonatomic, retain)MationList *mationListScroll;

@end

@implementation MationListTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    [self.tableView registerNib:[UINib nibWithNibName:@"ScrollTableViewCell" bundle:nil] forCellReuseIdentifier:@"scrollCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"NewestTableViewCell" bundle:nil] forCellReuseIdentifier:@"newsCell"];
    
    self.scrollPicArray = [NSMutableArray array];
    
    RequestMessageData *reqNewestMesData = [[RequestMessageData alloc] init];
    [reqNewestMesData requestMessageUrl:@"http://183.232.160.141/app.api.autohome.com.cn/autov4.8.0/news/newslist-pm2-c0-nt0-p1-s30-l0.json" reqSuccessBlockM:^(NSData *data) {
        NSDictionary *bigDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSDictionary *medianDic = [bigDic objectForKey:@"result"];
        self.mationListScroll = [[MationList alloc] init];
        for (NSDictionary *scrollDic in [medianDic objectForKey:@"focusimg"]) {
            self.mationListScroll.scrollPhotoUrl = [scrollDic objectForKey:@"imgurl"];
            [self.scrollPicArray addObject:self.mationListScroll.scrollPhotoUrl];
        }
//        for (NSDictionary *newestDic in <#collection#>) {
//            <#statements#>
//        }
    } reqErrorBlockM:^(NSError *error) {
        
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return 2;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    if (indexPath.section == 0 && indexPath.row == 0) {
//        static NSString *identifier = @"scrollCell";
        
        ScrollTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"scrollCell"];
        
        MationList *matData = self.mationListScroll;
        cell.mList = matData;
        NSLog(@"调用mList的set方法");
        return cell;
    }
//    static NSString *identifier = @"newsCell";
    NewestTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"newsCell"];
    
    
    
    NSLog(@"调用mList的set方法");
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        return 158;
    }
    return 90;
}


/*
 // Override to support conditional editing of the table view.
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the specified item to be editable.
 return YES;
 }
 */

/*
 // Override to support editing the table view.
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
 if (editingStyle == UITableViewCellEditingStyleDelete) {
 // Delete the row from the data source
 [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
 } else if (editingStyle == UITableViewCellEditingStyleInsert) {
 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
 }
 }
 */

/*
 // Override to support rearranging the table view.
 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
 }
 */

/*
 // Override to support conditional rearranging of the table view.
 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the item to be re-orderable.
 return YES;
 }
 */

/*
 #pragma mark - Table view delegate
 
 // In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 // Navigation logic may go here, for example:
 // Create the next view controller.
 <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:<#@"Nib name"#> bundle:nil];
 
 // Pass the selected object to the new view controller.
 
 // Push the view controller.
 [self.navigationController pushViewController:detailViewController animated:YES];
 }
 */

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
